//
//  UserCreditVoucher.m
//  Courses
//
//  Created by YiXuePxh on 15/5/18.
//  Copyright (c) 2015年 boyibang. All rights reserved.
//

#import "UserCreditVoucher.h"
#import "User.h"
@implementation UserCreditVoucher
-(id)initWithJsonDict:(NSDictionary* )jsonDict Result:(BOOL)result Msg:(NSString* )msg{
    self.result = result;
    self.msg = msg;
    if (jsonDict) {
        self.disCount = [jsonDict[@"discount"] floatValue];
        self.couponCode = jsonDict[@"couponCode"];
    }
    return self;
}
+(UserCreditVoucher* )getUserCreditVoucherWithCouponCode:(NSString* )couponCode{
    UserCreditVoucher* userCredit;
    Request* request = [Request requestWithName:@"check_coupon"];
    request.body[@"deviceNo"] = @"iOS12345";
    request.body[@"userId"] = [User currentUser].userId;
    request.body[@"couponCode"] = couponCode;
    NSDictionary* dicInfo = [[NSBundle mainBundle] infoDictionary];
    request.body[@"version"] = [dicInfo objectForKey:@"CFBundleShortVersionString"];
    request.body[@"sourceId"] = @"2";
    Response* response = [request response];
    if (response.result) {
        if ([response.content[@"coupon"] isKindOfClass:[NSDictionary class]]) {
            userCredit = [[UserCreditVoucher alloc]initWithJsonDict:response.content[@"coupon"] Result:response.result Msg:response.msg];
        }
    }else{
        userCredit = [[UserCreditVoucher alloc]initWithJsonDict:nil Result:response.result Msg:response.msg];
    }
    return userCredit;
}
@end
